#ifndef _MODULESCOPE_H_
#define _MODULESCOPE_H_
#include "Scope.h"
#include "ast/Module.h"
#include "../ErrorCodes.h"

class ModuleScope;
class LineBuilder: public VisitorBase
{
public:
    LineBuilder(ModuleScope *scope);
    virtual void traverse(const SimpleNodePtr& node);
protected:
    virtual void unhandled_node(const SimpleNodePtr&){}
private:
    ModuleScope *_scope;
};

class ModuleScope: public Scope
{
    Q_OBJECT
public:
    ModuleScope(const QFileInfo& fileName);
    virtual ~ModuleScope();
    friend class LineBuilder;
public:
    void buildScope();

    virtual void visitModule(const ModulePtr &node);

    ModulePtr ast(){return _moduleAst;}
    void setAst(const ModulePtr& moduleAst);
    QList<Error> errorList();
    QList<SimpleNodePtr> astInLine(int line);
    QList<SimpleNodePtr> astInText(const QString& text);
    void refresh(const QString& content);
    bool shiftAst(int fromPos, int removed, int added);
public slots:
    void onParseError(const QString& msg, int line, int col);
private:
    ModulePtr _moduleAst;
    QList<Error> _errorList;
    QMap<int, QList<SimpleNodePtr> > _lines;
    QMap<int, SimpleNodePtr > _poses;
    QMap<QString, QList<SimpleNodePtr> > _text;
};

#endif
